<?php /* Smarty version 2.6.20, created on 2012-08-10 15:13:19
         compiled from _core/_include/module/_mvc/control/handlecontainerreceipt.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/_include/module/_mvc/control/handlecontainerreceipt.tpl', 124, false),)), $this); ?>
function HandleContainerReceipt(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  
  this._orderTrackId = (options && options.track) ? options.track : [];
  
  this._createElements();
};

HandleContainerReceipt.prototype._createElements = function() {
  var _self = this;
  var refund = this._item._refund;
 
  
  for (var j = 0, jl = this._orderTrackId.length; j < jl; j++) {
    
    var order = DlmanageUtils.order(this._item.orders, this._orderTrackId[j]);
    var gui = this._gui.list[j];

	    if (order.cancelled == 1) {
	      continue;
	    }      
    
    gui.orderType.appendChild(document.createTextNode(order.type));
    gui.date.appendChild(document.createTextNode(SimpleDate.format(order.date)));
    
    gui.opackage.appendChild(document.createTextNode('Type of coverage selected     Photograhpy:'));
    var a = document.createElement('a');
        a.href = '#';
        a.appendChild(document.createTextNode(order.photoname));
    gui.opackage.appendChild(a);
    gui.opackage.appendChild(document.createTextNode('\u00A0\u00A0\u00A0\u00A0'+'Album:'));
    
    var album = MiscUtils.find(order.purchaseItems, [{ attrs: ['cancelled'], value: '0' },{ attrs: ['type'], value: 'Album' }, { attrs: ['packageInc'], value: 'Photo Package' }], MiscUtils.conjunction);
    var addp =  MiscUtils.find(order.purchaseItems, [{ attrs: ['packageInc'], value: '' }]);
    var a1 = document.createElement('a');
        a1.href = '#';
        a1.appendChild(document.createTextNode( (album[0])? album[0].name:'' ));
    gui.opackage.appendChild(a1);
    
   if(order.videoname!= ''){ 
    gui.ovpackage.appendChild(document.createTextNode('Type of coverage selected    Videograhpy:'));
    var a2 = document.createElement('a');
        a2.href = '#';
        a2.appendChild(document.createTextNode(order.videoname));
    gui.ovpackage.appendChild(a2);
    gui.ovpackage.appendChild(document.createTextNode('\u00A0\u00A0\u00A0\u00A0'+'Video:'));
    
    var album1 = MiscUtils.find(order.purchaseItems, [{ attrs: ['cancelled'], value: '0' },{ attrs: ['type'], value: 'Video' }, { attrs: ['packageInc'], value: 'Video Package' }], MiscUtils.conjunction);

    var vdstr ='';
    for(var iii = 0,ji = album1.length; iii < ji; iii++)
    {
       var vd = album1[iii];
       
       if(vd.model == 'Video DVD' || vd.model == 'Video DVD Blu-Ray')
       {
            vdstr += vd.name +'\u00A0\u00A0\u00A0\u00A0';
       }
    
    }

    //var addp =  MiscUtils.find(order.purchaseItems, [{ attrs: ['packageInc'], value: '' }]);
    var a12 = document.createElement('a');
        a12.href = '#';
        a12.appendChild(document.createTextNode( vdstr ));
    gui.ovpackage.appendChild(a12);
  }

    if(addp.length > 0)
    {
    	gui.oaddpackage.appendChild(document.createTextNode('Additions:'));
    }
    
    for(var ii = 0,iil = addp.length; ii < iil; ii++ )
    {
    	var padd = addp[ii];

	    if (padd.cancelled == 1) {
	      continue;
	    }    	
    	
        var a11 = document.createElement('a');
        a11.href = '#';
        a11.appendChild(document.createTextNode( (padd)? padd.name:''));
        gui.oaddpackage.appendChild(a11);
        gui.oaddpackage.appendChild(document.createTextNode('\u00A0\u00A0\u00A0\u00A0'));
    }
    
    
    

    var total = 0, stage = 0,itotal1 = 0,itotal2 = 0,itotal3 = 0,itotal4 = 0;
    for (var i = 0, il = order.payments.length; i < il; i++) {
      var p = order.payments[i];
      if (p.cancelled == 1) {
        continue;
      }
      if (p.stage == 1) itotal1 += parseFloat(p.amount, 10);
      if (p.stage == 2) itotal2 += parseFloat(p.amount, 10);
      if (p.stage == 3) itotal3 += parseFloat(p.amount, 10);
      if (p.stage == 4) itotal4 += parseFloat(p.amount, 10);
      
      total += parseFloat(p.amount, 10);
      stage = Math.max(stage, p.stage);
    }
    
    var rtotal = 0;
    
    for (var i = 0, il = refund.length; i < il; i++) {
      var r =refund[i];
      
      if (r.refundNo != order.e_oid) {
        continue;
      }
      if (r.status != -1) {
        rtotal += parseFloat(r.amount, 10);
      }
    }
      total = total - rtotal;
      order.refund = refund;
	
	if ('<?php echo ((is_array($_tmp=@BRANCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' == 'BNE' || '<?php echo ((is_array($_tmp=@BRANCH)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' == 'XTRAO') {
      var tolPrice = 0; price = 0; gst = 0;
      tolPrice = (order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2);
      price = (tolPrice / parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@TRUE_GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2);
      gst = (tolPrice - price).toFixed(2);
      gui.price1.appendChild(document.createTextNode('$' + price));
      gui.gst.appendChild(document.createTextNode('$' + gst));
      gui.price.appendChild(document.createTextNode((order.price > 0) ? '$' + tolPrice : '$0.00'));
      gui.received.appendChild(document.createTextNode('$' + total.toFixed(2)));
      gui.anticipated.appendChild(document.createTextNode('$' + ((order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)) - total).toFixed(2)));
    } else {
      gui.price.appendChild(document.createTextNode((order.price > 0) ? '$' + (order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      gui.received.appendChild(document.createTextNode('$' + total.toFixed(2)));
      gui.anticipated.appendChild(document.createTextNode('$' + ((order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)) - total).toFixed(2)));
    }
	
    //gui.price.appendChild(document.createTextNode((order.price > 0) ? '$' + (order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
    //gui.received.appendChild(document.createTextNode('$' + total.toFixed(2)));
    //gui.anticipated.appendChild(document.createTextNode('$' + ((order.price * parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10)) - total).toFixed(2)));
	
    
    var rules = DlmanageUtils.payment(order.type);
    if (rules[stage]) {
      gui.due.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[stage].rate - total).toFixed(2) > 0) ? '$' + (parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[stage].rate - total).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00')));
    } else {
      gui.due.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price - total).toFixed(2) > 0) ? '$' + (parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price - total).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00')));
    }
    
    if(refund.length >0)
    {
       gui.refundtitle.appendChild(document.createTextNode('Refund:'));
    }
    
    tabler = document.createElement('table');
    tabler.cellPadding = 0;
    tabler.cellSpacing = 0;
    gui.refund.appendChild(tabler);
    
    
    for (var i = 0, il = refund.length; i < il; i++) {
        var r =refund[i];
        
        if (r.refundNo != order.e_oid) {
          continue;
        }
        if (r.status != -1) {
    	    tr = tabler.insertRow(-1);
    	    td = tr.insertCell(-1);
    	    td.style.height = '15px';
    	    td.style.verticalAlign = 'middle';
    	    td.align = 'left';
    	    td.appendChild(document.createTextNode('$' + r.amount + ' '));
    	    
    	    
    	    td = tr.insertCell(-1);
    	    td.style.padding = '0px 4px';
    	    td.appendChild(document.createTextNode('paid on'));
    	    td = tr.insertCell(-1);
    	    
    	    td.appendChild(document.createTextNode('  ' +  SimpleDate.format(SimpleDate.fromStamp(r.payDate)) ));        	
          
        }
      }
    
    
    if (rules[0]) {
      gui.pay1.rate.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[0].rate) ).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[0].perc)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      gui.pay1.rate1.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[0].rate) - total).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[0].perc)- itotal1).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      this._pay(gui.pay1, order, 1, rules[0]);
    } else {
      gui.pay1.container.style.display = 'none';
    }
    if (rules[1]) {
  	 /* var itotal = 0;
	  for (var i = 0, il = order.payments.length; i < il; i++) {
	    var p = order.payments[i];
	    if (p.stage != 3 || p.cancelled == 1) {
	      continue;
	    }
	    
	    itotal += parseFloat(p.amount, 10);
	  }*/
    	
      gui.pay2.rate.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[1].rate) ).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[1].perc)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      gui.pay2.rate1.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[1].rate) - total).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[1].perc)- itotal2).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      this._pay(gui.pay2, order, 2, rules[1]);
    } else {
      gui.pay2.container.style.display = 'none';
    }
    if (rules[2]) {
    	  var itotal = 0;
    	  for (var i = 0, il = order.payments.length; i < il; i++) {
    	    var p = order.payments[i];
    	    if (p.stage != 3 || p.cancelled == 1) {
    	      continue;
    	    }
    	    
    	    itotal += parseFloat(p.amount, 10);
    	  }
      gui.pay3.rate.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[2].rate) ).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[2].perc)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      gui.pay3.rate1.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[2].rate) - total).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[2].perc)- itotal3).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      this._pay(gui.pay3, order, 3, rules[2]);
    } else {
      gui.pay3.container.style.display = 'none';
    }
    if (rules[3]) {
      gui.pay4.rate.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[3].rate) ).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[3].perc)).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      gui.pay4.rate1.appendChild(document.createTextNode((((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[3].rate) - total).toFixed(2) > 0) ? '$' + ((parseFloat(1 + parseFloat('<?php echo ((is_array($_tmp=@GST)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
'), 10) * order.price * rules[3].perc)- itotal4).toFixed(2) + ' (Inc. ' + '<?php echo ((is_array($_tmp=@TAX)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
' + ')' : '$0.00'));
      this._pay(gui.pay4, order, 4, rules[3]);
    } else {
      gui.pay4.container.style.display = 'none';
    }
  }
  window.print();
};
  
HandleContainerReceipt.prototype._pay = function(gui, order, stage, rule) {
  var table, tr, td, _self = this;

  gui.rate.appendChild(document.createTextNode(' ' + rule.title));
  
  table = document.createElement('table');
  table.cellPadding = 0;
  table.cellSpacing = 0;
  gui.payment.appendChild(table);
  
  var total = 0;

 
  for (var i = 0, il = order.pays.length; i < il; i++) {
	    var p = order.pays[i];
	    if (p.stage != stage || p.cancelled == 1) {
	      continue;
	    }
	    
	    //total += parseFloat(p.amount, 10);
	    tr = table.insertRow(-1);
	    td = tr.insertCell(-1);
	    td.style.height = '15px';
	    td.style.verticalAlign = 'middle';
	    td.align = 'left';
	    td.appendChild(document.createTextNode('$' + p.amount + ' '));
	    
	    
	    td = tr.insertCell(-1);
	    td.style.padding = '0px 4px';
	    td.appendChild(document.createTextNode('paid on'));
	    td = tr.insertCell(-1);
	    
	    td.appendChild(document.createTextNode(' ' + SimpleDate.format(p.date)));
	  }  
  
  //gui.payment.appendChild(document.createTextNode((total == 0) ? 'Pay ' + rule.comment.toLowerCase() : ''));
  
};